<?php
namespace Product\Form\Filter;

use Zend\InputFilter\InputFilter;
use Product\Form\ProductForm;

use Zend\InputFilter\Factory as InputFactory;
use Zend\InputFilter\InputFilterAwareInterface;
use Zend\InputFilter\InputFilterInterface;
use Zend\Validator\File\Size; //tried also with use Zend\Validator\File;


class ProductFilter extends InputFilter {

    public function __construct($dbAdapter){
        
        $isEmpty = \Zend\Validator\NotEmpty::IS_EMPTY;
        
        $this->add(array(
            'name' => 'namepro',
            'required' => true,
            'filters' => array(
                array('name' => 'StripTags'),
                array('name' => 'StringTrim'),
            ),
            'validators' => array(
                array(
                    'name' => 'NotEmpty',
                    'options' => array(
                        'messages' => array(
                            $isEmpty => 'Tên không được để trống.'
                        )
                    ),
                    'break_chain_on_failure' => true
                ),
            		/* array(
            			'name'    => '\Zend\Validator\StringLength',
                		 
                		'options' => array(
                				'encoding' => 'UTF-8',
                				'min'      => 4,
                				'max'      => 40,
                				'messages' => array(
                						\Zend\Validator\StringLength::TOO_SHORT => 'Tên phải nhập từ 4 đến 40 kí tự!',
                						'stringLengthTooLong' => 'Tên phải nhập từ 4 đến 40 kí tự!'
                				),
                		      ),
            				), */
            ),
        ));
        
        
        $this->add(array(
            'name' => 'contentpro',
            'required' => false,
           /*  'filters' => array(
                array('name' => 'StripTags'),
                array('name' => 'StringTrim'),
            ),
            'validators' => array(
                array(
                    'name' => 'NotEmpty',
                    'options' => array(
                        'messages' => array(
                            $isEmpty => 'Nội dung không để trống.'
                        )
                    )
                )
            ) */
        ));

        $selectsp = new ProductForm(null,$dbAdapter);
        $valselect = $selectsp->getOptionsForSelect();
        $arrselct = array();
        foreach ($valselect as $key => $val){
        	$arrselct[]=$key;
        }
        $this->add(array(
        		'name' => 'producttypes',
        		'required' => true,
        		'filters' => array(
        				array('name' => 'StripTags'),
        				array('name' => 'StringTrim'),
        		),
        		'validators' => array(
        				array(
        						'name' => 'NotEmpty',
        						'options' => array(
        								'type' => array(
					                        \Zend\Validator\NotEmpty::NULL,
					                     ),
        						)
        				),
        				array(
        						'name'   => 'InArray',
        						'options' => array(
        								'haystack' => $arrselct,
        								'strict' => \Zend\Validator\InArray::COMPARE_NOT_STRICT_AND_PREVENT_STR_TO_INT_VULNERABILITY,
        								'messages' => array(
        										\Zend\Validator\InArray::NOT_IN_ARRAY => 'Vui lòng chọn loại sản phẩm.',
        								),
        						),
        				),
        		)
        ));
        
        
    /*   $this->add(array(
                'name' => 'file_upload',
                'required' => true,
                'validators' => array(
                    array(
                        'name' => 'NotEmpty',
                        'options' => array(
                            'messages' => array(
                                'isEmpty' => 'Please select an icon to upload.',
                            ),
                        ),
                    ),
                		array(
                				'name' => '\Zend\Validator\File\IsImage',
                				'options' => array(
                						            'magicFile' => false
                						
                				),
                		),
                    array(
                        'name' => '\Zend\Validator\File\IsImage',
                        'options' => array(
                            'messages' => array(
                                'fileIsImageFalseType' => 'Please select a valid icon image to upload.',
                                'fileIsImageNotDetected' => 'The icon image is missing mime encoding, please verify you have saved the image with mime encoding.',
                            ),
                        ),
                    ),
                ),
            )); */
    }
}